package com.you.atlas.web.place.module.screen;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.Navigator;
import com.alibaba.citrus.turbine.dataresolver.Param;
import com.you.atlas.biz.place.service.NoteQueryService;
import com.you.atlas.biz.place.service.NoteService;
import com.you.common.webx.AuthContext;
import com.you.place.dal.dao.dataobject.NoteDO;

public class NoteDelete {

    @Autowired
    private NoteService      noteService;

    @Autowired
    private NoteQueryService noteQueryService;

    public void execute(@Param("from") String from, @Param("noteId") Long noteId, Navigator navigator) {

        Long memberId = AuthContext.getContext().getMemberId();
        NoteDO noteDO = noteQueryService.find(noteId);

        if (noteDO == null || !memberId.equals(noteDO.getMemberId())) {
            navigator.redirectTo("homeModule").withTarget("error.vm");
            return;
        }
        noteService.removeNote(noteId);
        if ("member".equals(from)) {
            navigator.redirectTo("memberModule").withTarget("noteList.vm").withParameter("id",
                                                                                         memberId.toString());
        } else {

            navigator.redirectTo("placeModule").withTarget("noteList.vm").withParameter("id",
                                                                                        noteDO.getPlaceId().toString());
        }

    }

}
